package com.dengdai.applibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @说明 折叠列表基本类
 * @作者 LY
 * @时间 16/5/24 08:52
 * @邮箱 2743569843@qq.com
 * @版权 Copyright(c) 2016 LY-版权所有
 * @备注
 */
public class BaseCommExpandableListAdapter extends BaseExpandableListAdapter {
    protected List<Object> listGroupData = new ArrayList<Object>();
    protected List<List<Object>> listChildrenData = new ArrayList<List<Object>>();
    protected Context mContext;
    protected LayoutInflater inflater;

    public BaseCommExpandableListAdapter(Context mContext) {
        this.mContext = mContext;
        this.inflater = LayoutInflater.from(mContext);
    }

    /**
     * 设置分组列表数据
     *
     * @param listData
     */
    public void setList(List<Object> listData, List<List<Object>> listChildrenData) {
        if (listData != null && listData.size() > 0) {
            this.listGroupData.addAll(listData);
        }
        if (listChildrenData != null && listChildrenData.size() > 0) {
            this.listChildrenData.addAll(listChildrenData);
        }
        notifyDataSetChanged();
    }

    /**
     * 清理数据
     */
    public void clear() {
        this.listGroupData.clear();
        this.listChildrenData.clear();
        notifyDataSetChanged();
    }


    @Override
    public int getGroupCount() {
        return listGroupData == null ? 0 : listGroupData.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return listChildrenData == null ? 0 : (listChildrenData.get(groupPosition) == null ? 0 : listChildrenData.get(groupPosition).size());
    }

    @Override
    public Object getGroup(int groupPosition) {
        return listGroupData == null ? null : listGroupData.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return listChildrenData == null ? null : (listChildrenData.get(groupPosition) == null ? null : listChildrenData.get(groupPosition).get(childPosition));
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        return null;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        return null;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
